operator delete, operator delete[]
From Cppreference
| C++ Standard Library | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Utilities library | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Dynamic memory management | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Low level memory management | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Template:cpp/memory/new/sidebar content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Defined in header <new>
| ||
| void operator delete ( void * ptr );
| (1) | |
| void operator delete[]( void * ptr );
| (2) | |
Deallocates memory, previously allocated by an allocation function, by either operator new or operator new[]. The ptr must be pointer, previously obtained by call to corresponding allocation function. For single allocated objects the first version of the expression must be used, whereas for arrays the second version must be used. Whether deallocation of memory, which was allocated by placement allocation function, needs to be performed and which deallocation function to invoke, is mandated by the particular allocation algorithm used by the program to allocate memory.
Contents |
[edit] Replacing and overloading
The program can implement both deallocation functions, which would then be used instead of the default implementations. Also, program can add versions of deallocation functions with different signatures. In this way it is possible to implement consistent interface to deallocate memory allocated by placement allocation functions.
The deallocation function can be replaced/overloaded in two ways:
- in the global scope: in order to call it, the signature of the overloaded allocation functions must be visible at the place of deallocation, except for implicitly declared default deallocation functions. This allocation function will be used for all deallocations with corresponding parameters in the current program
- in the local scope: the overloaded operator delete must be static public member function of the class. This deallocation function will be used only for deallocations of that particular class.
During compilation, each delete expression looks up for appropriate deallocation function's name firstly in the class scope and after that in the global scope. It can be instructed to skip the first step. Note, that as per overloading rules, any deallocation functions declared in class scope hides all global deallocation functions. For more information see delete expression.
[edit] Parameters
| ptr | - | pointer to a memory area to deallocate |
[edit] Return value
(none)
[edit] Exceptions
(none)